﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Tdb.YY.BLL;
using Tdb.YY.DTO;
using Tdb.YY.DTO.YY;

namespace Tdb.YY.API.Controllers
{
    /// <summary>
    /// yy1
    /// </summary>
    public class YY1Controller : BaseController
    {
        #region 变量

        /// <summary>
        /// YY1 逻辑层
        /// </summary>
        private YY1BLL bll = new YY1BLL();

        #endregion

        #region 接口

        /// <summary>
        /// 查询YY1类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("QueryCType")]
        [ResponseCache(VaryByHeader = "Accept-Encoding", Location = ResponseCacheLocation.Any, Duration = 1800)]
        public async Task<ResultList<YYCTypeListInfo>> QueryCTypeAsync()
        {
            var list = await this.bll.QueryCTypeAsync();
            return new ResultList<YYCTypeListInfo>(true, "OK", list);
        }

        /// <summary>
        /// 查询YY1列表
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        [HttpGet]
        [Route("QueryList")]
        [ResponseCache(VaryByHeader = "Accept-Encoding", Location = ResponseCacheLocation.Any, Duration = 1800)]
        public async Task<ResultPageList<YYListInfo>> QueryListAsync([FromQuery]YYListReq req)
        {
            var list = await this.bll.QueryListAsync(req);
            return new ResultPageList<YYListInfo>(true, "OK", list, req.GetStartNum(), list.TotalRecord);
        }

        /// <summary>
        /// 过滤YY1列表
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        [HttpGet]
        [Route("FilterList")]
        [ResponseCache(VaryByHeader = "Accept-Encoding", Location = ResponseCacheLocation.Any, Duration = 1800)]
        public async Task<ResultPageList<YYListInfo>> FilterListAsync([FromQuery]YYFilterListReq req)
        {
            var list = await this.bll.FilterListAsync(req);
            return new ResultPageList<YYListInfo>(true, "OK", list, req.GetStartNum(), list.TotalRecord);
        }

        /// <summary>
        /// 获取YY1信息
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetByID")]
        public async Task<ResultInfo<YYInfo>> GetByIDAsync([FromQuery]IDReq req)
        {
            var item = await this.bll.GetByIDAsync(req.ID);
            return new ResultInfo<YYInfo>(true, "OK", item);
        }

        /// <summary>
        /// 查询异常记录url列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("QueryErrorUrl")]
        public async Task<ResultList<string>> QueryErrorUrlAsync()
        {
            var list = await this.bll.QueryErrorUrlAsync();
            return new ResultList<string>(true, "OK", list);
        }

        /// <summary>
        /// 删除异常记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("DeleteErrorInfo")]
        public async Task<ResultInfo<int>> DeleteErrorInfoAsync()
        {
            var count = await this.bll.DeleteErrorInfoAsync();
            return new ResultInfo<int>(true, "OK", count);
        }

        /// <summary>
        /// 标题重复的记录去重
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("DistincTitle")]
        public async Task<ResultInfo<int>> DistincTitleAsync()
        {
            var count = await this.bll.DistincTitleAsync();
            return new ResultInfo<int>(true, "OK", count);
        }

        /// <summary>
        /// 修改权重
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        [HttpPost]
        [Route("ModifyRight")]
        public async Task<ResultInfo<bool>> ModifyRightAsync(YYModifyRightReq req)
        {
            await this.bll.ModifyRightAsync(req);
            return new ResultInfo<bool>(true, "OK", true);
        }

        #endregion
    }
}